home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / SINDEX.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  577 b   |  23 lines

  1. /* sindex.c - first occurence of a char in a string  */
  2. #include "stdio.h"
  3.  
  4. #define FAILURE  -1        /* return value if string not found */
  5.  
  6. int  sindex(c,s)        /* find char in string - return position */
  7.   int    c  ;            /* char to br found  */
  8.   char    s[]   ;         /* string in which to look for c  */
  9.   {
  10.      int   i  ;
  11.  
  12.      i    =  0  ;
  13.      while( s[i] != '\0' )      /* stop at end of the string  */
  14.     {  if( c == s[i] )
  15.        return( i )     ;    /* c found - return its position  */
  16.        i  =  i  +  1 ;
  17.     }
  18.      /* c was not found in s */
  19.      return ( FAILURE ) ;
  20.   }
  21.  
  22.  
  23.